package response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2022-03-22-15:06 15:06
 */
@WebServlet("/myResponse3")
public class MyResponse3 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*//获取流之前，设置流的编码格式。默认格式为：ISO-8859-1，改为：GBK。
        response.setCharacterEncoding("GBK");
        //告诉浏览器使用GBK进行解码。浏览器默认使用GBK进行解码
        response.setHeader("Content-Type","text/html;charset=GBK");*/
        //简单形式设置编码，注意要放在流的前面，否则无法影响流的编码格式
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();

        writer.write("吃啊");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
